package com.hongliang.netty01.future;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * @author Hongliang Zhu
 * @create 2021-09-25 18:19
 */
@SuppressWarnings("AlibabaThreadPoolCreation")
@Slf4j
public class TestJdkFuture {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //  1. 线程池
        ExecutorService service = Executors.newFixedThreadPool(2);
        Future<Integer> future = service.submit(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                log.debug("执行计算...");
                Thread.sleep(1000);
                return 50;
            }
        });
        log.debug("等待结果");
        log.debug("结果是：{}" , future.get());
    }
}
